package tool

import (
	"math"
	"strings"
)

const keywords = `
天堂恋人
Jannat axik liri
ISIS
Islam Doliti
东伊运
Xarki Turkistan Islam Partiyasi
东突伊斯兰杂志
Xarkiy Tvrkistan Islam geziti
伊斯兰之声周报
Islam Awazi haptilik geziti
天堂的属性
Jannatnig Supatliri
宗教劝解
Dini Nasihatlar
热巴特之地
Ribat Zimini
伊斯兰道德
Islam Ahlak Maripi
都尔黑哲月的圣训
Zulhaj Eyidiki Hadis
来白圣战前线的呼声 
jihad Aldinki Sipidin Kalgan Nida
古兰经的捍
Kurannig Himayigiliri
`

func init() {
	items := strings.Split(keywords, "\n")
	for _, item := range items {
		item = strings.TrimSpace(item)
		if item != "" {
			if len(item) < Sensitive.minLen {
				Sensitive.minLen = len(item)
			}
			Sensitive.keywords = append(Sensitive.keywords, item)
		}
	}
}

var Sensitive = &sensitive{
	minLen: math.MaxUint8,
}

type sensitive struct {
	keywords []string
	minLen   int
}

func (r *sensitive) Keywords() []string {
	return r.keywords
}

func (r *sensitive) Filter(source string) string {
	if len(source) >= r.minLen {
		for _, keyword := range r.keywords {
			source = strings.ReplaceAll(source, keyword, "***")
		}
	}

	return source
}
